package alo.p6.work5;

import alo.p6.BinarySearchTreeNode;

/**
 * @ClassName PruneBST
 * @Description 给定一棵BST树和两个整数，删除树中所有不再区间的元素
 * @Author Fanxc
 * @DATE 2021/3/8 22:43
 * @Version 1.0
 */
public class PruneBST {
    BinarySearchTreeNode PrunrBST(BinarySearchTreeNode root,int a,int b){
        if (root==null){
            return null;
        }
        root.setLeft(PrunrBST(root.getLeft(),a,b));
        root.setRight(PrunrBST(root.getRight(),a,b));
        if (a<= root.getData()&&root.getData()>=b){
            return root;
        }else if (root.getData()>a){
            return root.getRight();
        } else {
            return root.getLeft();
        }
    }
}
